<?
session_start();
include("ajax_base.php");
include("../../../webkit/include/simple_db.php");
$db = new SimpleDB();

$action = $_GET['action'];

if($action == "list") {
	$condition = "user_name='".$_GET['user_name']."'";
	if(isset($_GET['date_range'])) {
		$arr = explode("_", $_GET['date_range']);
		$condition .= " and call_time between ".$arr[0]." and ".$arr[1];
	}
	$sql = "select id,caller,called,call_time,calling_seconds, user_name from hncc_missing_call where $condition order by id desc"; 
	echo to_grid_json($db, $sql, $dic_data, array("caller"=>"telephone_mapper", "calling_seconds"=>"calling_seconds_mapper"));

} else if($action == "add") {
	$sql = "insert into hncc_missing_call(caller,called,call_time,user_name, calling_seconds) values('".$_GET['caller']."','".$_GET['called']."','".date("Y-m-d H:i:s")."','".$_GET['user_name']."','".$_GET['calling_seconds']."')"; 
	$db->query($sql);
	echo "ok";
} 

function get_config_caller($u) {
	$config = array('hrxjyh'=>'4008296599');
	return $config[$u];
}

function telephone_mapper($v, $arr) {
	$str =  "<font color=red>$v</font>";
	if($arr['call_result'] == 0) {
		$str .= "&nbsp;<iframe src=\'http://222.240.139.227:9080/agent_event/callout_button.jsp?caller=".get_config_caller($arr['user_name'])."&called=".$v."&iconSize=15\' width=16 height=16 frameborder=0 marginheight=0 marginwidth=0 scrolling=no align=top></iframe>";
	}
	return $str;
}

function calling_seconds_mapper($v) {
	return $v / 1000;
}



?>